import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbpms.config.SpringConfig;
import com.dbpms.mapper.StudentManageMapper;
import com.dbpms.pojo.StudentInfo;
import com.dbpms.service.IStudentManageService;
import com.dbpms.service.IUserService;
import com.dbpms.service.ItestService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class test2 {

    @Autowired
    private IUserService userService;
    @Autowired
    private ItestService itestService;

    @Autowired
    private IStudentManageService iStudentManageService;
    // 分页查询
    @Test
    public void test1(){
        // 1.准备分页条件
        int pageNo = 2,pageSize = 2;

        // 1.2.排序参数
//        page.addOrder(new OrderItem("user_id",true));
        // 1.3.分页查询
        Page<StudentInfo> p = iStudentManageService.page(Page.of(pageNo,pageSize));

        // 2.解析
        // 总条数
        System.out.println("total = "+p.getTotal());
        // 总页数
        System.out.println("pages = "+p.getPages());
        // 分页数据
        List<StudentInfo> records = p.getRecords();
        records.forEach(System.out::println);
    }
//      records.forEach(record -> {
//        // 对每条记录执行的操作
//        System.out.println(record); // 例如，打印每条记录的内容
//    });
    @Resource
    private StudentManageMapper mapper;
    // 分页查询
    @Test
    public void test2(){
        IPage page = new Page(1,2);
        mapper.selectPage(page,null);
        System.out.println(page.getCurrent());
        System.out.println(page.getTotal());
        System.out.println(page.getPages());
        System.out.println(page.getRecords());
    }
}
